﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace CWMKliens
{
    public partial class FormChat : Form
    {
        CWMOsztalyok.Profil profil;

        public FormChat()
        {
            InitializeComponent();
        }
        public FormChat(CWMOsztalyok.Profil profil)
        {
            InitializeComponent();
            this.profil = profil;
            this.sajatVezerlo1.Profil = profil;
            this.sajatVezerlo1.IsmerosLista.DoubleClick += new EventHandler(IsmerosLista_DoubleClick);
            this.chatVezerlo1.TabControl.SelectedIndexChanged += new EventHandler(TabControl_SelectedIndexChanged);
        }

        void TabControl_SelectedIndexChanged(object sender, EventArgs e)
        {   
            
            foreach (CWMOsztalyok.Profil p in profil.Kapcsolatok)
            {
                if (p.Email == ((TabControl)sender).SelectedTab.Text)
                {
                    this.vendegVezerlo1.Profil = p;
                    break;
                }
            }
            
        }

        void IsmerosLista_DoubleClick(object sender, EventArgs e)
        {
            this.chatVezerlo1.TabControl.TabPages.Add(((ListBox)sender).SelectedItem.ToString());
        }

        private void megjelenítendőKépVáltásaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //ezt érdemes majd átírni
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {                
                
                FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open);
                byte[] pic = new byte[fs.Length];                
                fs.Read(pic, 0, (int)fs.Length);
                fs.Close();
                ProfilKezelo.ProfilKezelo pk = new ProfilKezelo.ProfilKezelo();
                pk.KepFeltolt(pic, this.profil.Email);
                sajatVezerlo1.Kep = Image.FromFile(openFileDialog1.FileName); 
            }
        }

        private void chatVezerlo1_Klikk(object sender, EventArgs e)
        {
            MessageBox.Show("Klikk");
        }

        private void újToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ProfilKezelo.ProfilKezelo pk = new ProfilKezelo.ProfilKezelo();
            UjKapcsolatForm ukf=new UjKapcsolatForm();
            ukf.ShowDialog();
            pk.UjKapcsolat(this.profil.Email, ukf.Partner);

        }
    }
}
